// pages/rent/rent.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region:"",
    area:"",
    id:0,
    isjiantou:true,   //箭头切换
    selectcontent:[
      
    ],
    show:false,
    value:undefined,   //选中的值
    valueid:undefined,  //选中的id
    house_name:"",
    house_budget:"",
    house_product:"",
    house_title:"",
    house_text:"",
    ids:""
  },
  getUserProvince:function(e)
  {
     this.setData({
         region:e.detail.value     //将用户选择的省市区赋值给region
     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  key(e){
    this.setData({
      id:e.currentTarget.dataset.id
    })
  },
  house_name(e){
    this.setData({
      house_name: e.detail.value
    })
   
  },
  house_budget(e){
    this.setData({
      house_budget: e.detail.value
    })
  },
  house_product(e){
    this.setData({
      house_product: e.detail.value
    })
  },
  house_title(e){
    this.setData({
      house_title: e.detail.value
    })
  },
  house_text(e){
    this.setData({
      house_text: e.detail.value
    })
  },
  // 下拉框收起和下拉
  changejiantou(){
    this.setData({
      isjiantou:!this.data.isjiantou,
      show:true
    })
  },
  // 选择数据后回显
  changecontent(e){
    console.log(e)
    this.setData({
      value:e.currentTarget.dataset.datavalue.house_type_name,
      valueid:e.currentTarget.dataset.datavalue.id,
      isjiantou:true,
      show:false
    })
  },
  onLoad(options) {
    wx.request({
      url: 'http://www.house.com/index.php/house/type',
      success:res=>{
        this.setData({
          selectcontent:res.data.data,
          ids:options.id
        })
        console.log(this.data.selectcontent)
      }
    })
  },
  add(){
    var house_name=this.data.house_name;
    var house_budget=this.data.house_budget; 
    var house_product=this.data.house_product; 
    var house_title=this.data.house_title; 
    var house_text=this.data.house_text; 
    var house_type=this.data.valueid;
    var key = this.data.id
    if(key!=1){
      wx.showToast({
        title: '请阅读宏业找房',
      })
      return false
    }
    if(!house_budget||!house_product||!house_title||!house_text||!house_type){
      wx.showToast({
        title: '有空值',
      })
      return false
    }
    wx.request({
      url: 'http://www.house.com/index.php/house/add',
      method:"POST",
      header:{token:wx.getStorageSync('token')},
      data:{
        house_name:house_name,
        house_budget:house_budget,
        house_product:house_product,
        house_title:house_title,
        house_text:house_text,
        house_region:this.data.region,
        house_type:house_type,
        house_rent_and_purchase:this.data.ids
      },
      success:res=>{
        console.log(res.data.data.id)
        if(res.data.code==200){
            wx.navigateTo({
              url: '/pages/payH5/payH5?houseId='+res.data.data.id + "&type="+3,
            })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})